<template>
  <div>
     <Row>
        <input v-model="gameId" placeholder="游戏id,不填为所有游戏" ></input>
        <input v-model="bussiness" placeholder="渠道号" ></input>
        <Date-picker v-model="startMonth" placeholder="开始月" format="yyyy-MM"></Date-picker>
        <Date-picker v-model="endMonth" placeholder="结束月" format="yyyy-MM"></Date-picker>
        <Button type="primary" @click="onSearch">查询</Button>
    </Row>
    <Table :border="true" :stripe="true" :show-header="true" :data="tableData" :columns="tableColumns"></Table>
    <Page class="bottom-page" :total="totalPage" :current="crtPage" :page-size="pageSize" show-total show-elevator @on-change="onChange"></Page>
  </div>
</template>
<script>

import {getMonthAnalys} from '@/api/recharge.js'
import {getVO} from '@/common/proto-vo.js'
export default {
  data () {
    return {
      tableData: [],
      startMonth: '',
      endMonth: '',
      gameId: '',
      bussiness: '',
      crtPage: 1,
      totalPage: 0,
      pageSize: 10
    }
  },
  created () {
    this.onSearch()
  },
  methods: {
    onSearch () {
      let tgameId = 0
      let sSendMonth = 0
      let eSendMonth = 0
      let tBussiness = 0
      if (this.startMonth !== '' && this.endMonth !== '') {
        let sMonth = new Date(this.startMonth)
        let eMonth = new Date(this.endMonth)
        sSendMonth = '' + sMonth.getFullYear() + ((sMonth.getMonth() + 1) < 10 ? '0' + (sMonth.getMonth() + 1) : (sMonth.getMonth() + 1))
        eSendMonth = '' + eMonth.getFullYear() + ((eMonth.getMonth() + 1) < 10 ? '0' + (eMonth.getMonth() + 1) : (eMonth.getMonth() + 1))
        sSendMonth = parseInt(sSendMonth)
        eSendMonth = parseInt(eSendMonth)
      }

      if (this.gameId !== '') {
        tgameId = parseInt(this.gameId)
      }
      if (this.bussiness !== '') {
        tBussiness = parseInt(this.bussiness)
      }
      console.log('gameId:', tgameId, ',sSendMonth:', sSendMonth, ',eSendDay:', eSendMonth, ',bussiness:', tBussiness)
      getMonthAnalys(this.crtPage, this.pageSize, tgameId, sSendMonth, eSendMonth, tBussiness).then((data) => {
        if (!data) {
          return
        }
        this.tableData = []
        let RechargeAnalysVO = getVO('RechargeAnalysVO')
        let pv = data.data.data
        let len = pv.data.length
        for (let i = 0; i < len; i++) {
          let vo = RechargeAnalysVO.decode(pv.data[i])
          vo.bussiness = vo.bussiness.toNumber()
          this.tableData.push(vo)
        }
        this.totalPage = pv.intValues[1]
        console.log(this.tableData)
      })
    },
    onChange (item) {
      console.log(item)
      this.crtPage = item
      this.onSearch()
    }
  },
  computed: {
    tableColumns () {
      let cols = [
        {
          title: '时间',
          key: 'time',
          align: 'center'
        },
        {
          title: '游戏id',
          key: 'gameId',
          align: 'center'
        },
        {
          title: '充值量',
          key: 'amount',
          align: 'center'
        },
        {
          title: '充值玩家数',
          key: 'userNum',
          align: 'center'
        },
        {
          title: '新增充值玩家数',
          key: 'newUserNum',
          align: 'center'
        },
        {
          title: '渠道号',
          key: 'bussiness',
          align: 'center'
        }
      ]
      return cols
    }
  }
}

</script>

<style scoped>
.log-str{
  font-size: 14px;
  margin-bottom: 2px;
}
.content{
  min-height: 460px;
}
.bottom-page{
  margin-top: 5px;
  margin-bottom: 10px;
  float: right;
}
</style>
